package com.gkd.common;

import com.gkd.util.JwtUtil;
import lombok.Data;

import java.util.HashMap;

@Data
public class Result {
    private int code;
    private String msg;
    private int total;
    private Object data;
    private String token;
    public static String jwt = "token";


    public static Result err() {
        return result(400, "登录失败~", 0, null);
    }

    public static Result fail() {
        return result(400, "暂无数据~", 0, null);
    }

    public static Result suc(Object data) {
        return result(200, "登录成功", 0, data, JwtUtil.createToken(jwt));
    }

    public static Result suc(int total, Object data) {
        return result(200, "获取数据成功", total, data);
    }

    public static Result addFail(int total, String msg) {
        return result(400, msg, total, null);
    }

    public static Result registerFail(int total, String msg) {
        return result(400, msg, total, null);
    }

    public static Result addSuc(int total) {
        return result(200, "新增数据成功", total, null);
    }

    public static Result registerSuc(int total) {
        return result(200, "注册用户成功", total, null);
    }


    public static Result deleteSuc(int total) {
        return result(200, "删除数据成功", total, null);
    }

    public static Result deleteFail(int total) {
        return result(400, "删除数据失败", total, null);
    }

    public static Result updateFail(int total,String msg) {
        return result(400, msg, total, null);
    }

    public static Result updateSuc(int total) {
        return result(200, "修改数据成功", total, null);
    }


    public static Result result(int code, String msg, int total, Object data) {
        Result result = new Result();
        result.setTotal(total);
        result.setMsg(msg);
        result.setData(data);
        result.setCode(code);
        return result;
    }

    public static Result result(int code, String msg, int total, Object data, String token) {
        Result result = new Result();
        result.setTotal(total);
        result.setMsg(msg);
        result.setData(data);
        result.setCode(code);
        result.setToken(token);
        return result;
    }
}
